﻿// Xshell Command Attribute - Provides metadata for a command
// 
// <copyright file="XsCommandAttribute.cs" company="TaskyMedia LLC">
//   Copyright © 2010 TaskyMedia LLC
// </copyright>

namespace Xshell
{
    using System;

    /// <summary>
    /// Provides metadata for a command.
    /// </summary>
    public class XsCommandAttribute : Attribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="XsCommandAttribute"/> class.
        /// </summary>
        /// <param name="name">The name of the command.</param>
        public XsCommandAttribute(string name)
        {
            this.Name = name;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="XsCommandAttribute"/> class.
        /// </summary>
        /// <param name="name">The name of the command; used to recognize Xml elements.</param>
        /// <param name="commandArgsContainerType">Type of the command args container.</param>
        public XsCommandAttribute(string name, Type commandArgsContainerType)
            : this(name)
        {
            if (!typeof(IXsCommandArgs).IsAssignableFrom(commandArgsContainerType))
            {
                throw new InvalidOperationException(String.Format("'{0}' does not implement IXsCommandArgs", commandArgsContainerType.FullName));
            }

            this.CommandArgsContainerType = commandArgsContainerType;
        }

        /// <summary>
        /// Gets or sets the command name.
        /// </summary>
        /// <value>The command name.</value>
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the type of the command arguments container.
        /// </summary>
        /// <value>The type of the command arguments container.</value>
        public Type CommandArgsContainerType { get; set; }
    }
}
